package com.podium.web.log.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.podium.comment.AjaxResult;
import com.podium.comment.annotate.OperateLog;
import com.podium.comment.annotate.PermAuth;
import com.podium.comment.constant.OperateLogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.podium.web.log.entity.SysOperateLog;
import com.podium.web.log.service.SysOperateLogService;

import java.util.List;

/**
 * @author 邵文泽
 * @description 系统操作日志表
 * @date 2025-05-12 09:05:37
 */
@RestController
@RequestMapping("/log/operate/log")
public class SysOperateLogController {

    @Autowired
    private SysOperateLogService sysOperateLogService;

    /**
     * 分页获取系统操作日志表信息
     *
     * @param sysOperateLog 查询系统操作日志表信息条件
     */
    @PermAuth("log:operate_log:list")
    @GetMapping("page")
    public AjaxResult<IPage<SysOperateLog>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                    @RequestParam(defaultValue = "10") int pageSize,
                                                    SysOperateLog sysOperateLog
    ) {
        Page<SysOperateLog> page = new Page<>(pageNum, pageSize);
        return new AjaxResult<IPage<SysOperateLog>>().success(sysOperateLogService.page(page, sysOperateLog));
    }

    /**
     * 获取系统操作日志表信息
     *
     * @param sysOperateLog 查询系统操作日志表信息条件
     */
    @PermAuth("log:operate_log:list")
    @GetMapping("list")
    public AjaxResult<List<SysOperateLog>> getList(SysOperateLog sysOperateLog) {
        return new AjaxResult<List<SysOperateLog>>().success(sysOperateLogService.list(sysOperateLog));
    }

    /**
     * 根据ID获取系统操作日志表信息
     */
    @GetMapping("{id}")
    public AjaxResult<SysOperateLog> getByInfo(@PathVariable String id) {
        return new AjaxResult<SysOperateLog>().success(sysOperateLogService.getById(id));
    }

    /**
     * 添加系统操作日志表信息
     *
     * @param sysOperateLog 系统操作日志表信息
     */
    @OperateLog(title = "系统操作日志表", businessType = OperateLogType.ADD)
    @PermAuth("log:operate_log:add")
    @PostMapping("/save")
    public AjaxResult<Void> save(@RequestBody SysOperateLog sysOperateLog) {
        boolean row = sysOperateLogService.save(sysOperateLog);
        return row ? new AjaxResult<Void>().success() : new AjaxResult<Void>().error();
    }

    /**
     * 更新系统操作日志表信息
     *
     * @param sysOperateLog 系统操作日志表信息
     */
    @OperateLog(title = "系统操作日志表", businessType = OperateLogType.EDIT)
    @PermAuth("log:operate_log:edit")
    @PostMapping("/update")
    public AjaxResult<Void> update(@RequestBody SysOperateLog sysOperateLog) {
        boolean row = sysOperateLogService.updateById(sysOperateLog);
        return row ? new AjaxResult<Void>().success() : new AjaxResult<Void>().error();
    }

    /**
     * 删除系统操作日志表信息
     *
     * @param ids 系统操作日志表信息ID集合
     */
    @OperateLog(title = "系统操作日志表", businessType = OperateLogType.DELETE)
    @PermAuth("log:operate_log:delete")
    @GetMapping("/remove/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        if (ids == null || ids.length == 0) {
            return new AjaxResult<Void>().error("没有要删除的数据！");
        }
        for (Long id : ids) {
            sysOperateLogService.removeById(id);
        }
        return new AjaxResult<Void>().success();
    }

}